package com.anita.member.domain.model.member;

import com.anita.member.common.exception.BusinessException;

/**
 * 昵称值对象
 * @author qiu
 * @date 2025/10/17
 * @description
 */
public record Nickname(String value){

    public Nickname {
        if (value == null || value.trim().isEmpty()) {
            throw new BusinessException("会员昵称不能为空");
        }
        if (value.length() < 2 || value.length() > 20) {
            throw new BusinessException("会员昵称长度必须在2-20个字符之间");
        }
    }

    public static Nickname of(String s) {
        String trimmed = s==null? null : s.trim();
        return new Nickname(trimmed);
    }

    public String getValue() {
        return value;
    }
}
